package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WpsFiles;
import com.ruoyi.system.service.IWpsFilesService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/system/files")
public class WpsFilesController extends BaseController
{
    @Autowired
    private IWpsFilesService wpsFilesService;

    /**
     * 查询文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:list')")
    @GetMapping("/list")
    public TableDataInfo list(WpsFiles wpsFiles)
    {
        startPage();
        List<WpsFiles> list = wpsFilesService.selectWpsFilesList(wpsFiles);
        return getDataTable(list);
    }

    /**
     * 导出文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:files:export')")
    @Log(title = "文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WpsFiles wpsFiles)
    {
        List<WpsFiles> list = wpsFilesService.selectWpsFilesList(wpsFiles);
        ExcelUtil<WpsFiles> util = new ExcelUtil<WpsFiles>(WpsFiles.class);
        util.exportExcel(response, list, "文件信息数据");
    }

    /**
     * 获取文件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wpsFilesService.selectWpsFilesById(id));
    }

    /**
     * 新增文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:add')")
    @Log(title = "文件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WpsFiles wpsFiles)
    {
        return toAjax(wpsFilesService.insertWpsFiles(wpsFiles));
    }

    /**
     * 修改文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:edit')")
    @Log(title = "文件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WpsFiles wpsFiles)
    {
        return toAjax(wpsFilesService.updateWpsFiles(wpsFiles));
    }

    /**
     * 删除文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:files:remove')")
    @Log(title = "文件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wpsFilesService.deleteWpsFilesByIds(ids));
    }
}
